package cn.com.utt.common.exception;

import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.log4j.Logger;

public class BusinessException extends Exception {
	private static final long serialVersionUID = 1L;
	private Throwable cause;
	private static Logger logger = Logger.getLogger(BusinessException.class);

	public BusinessException(String msg) {
		super(msg);
		logger.error(msg);
	}

	public BusinessException(Throwable e) {
		super(e.getMessage());
		this.cause = e;
		logger.error(e.getMessage(), e);
	}

	public BusinessException(String msg, Throwable e) {
		super(msg);
		this.cause = e;
		logger.error(msg, e);
	}

	public Throwable getCause() {
		return this.cause;
	}

	public void printStackTrace(PrintStream ps) {
		if (getCause() == null) {
			super.printStackTrace(ps);
		} else {
			ps.println(this);
			getCause().printStackTrace(ps);
		}
	}

	public void printStackTrace(PrintWriter pw) {
		if (getCause() == null) {
			super.printStackTrace(pw);
		} else {
			pw.println(this);
			getCause().printStackTrace(pw);
		}
	}

	public void printStackTrace() {
		printStackTrace(System.err);
	}
}
